class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        char2id = {}
        lastSubstrEndPos = -1
        res = 0
        
        for curPos in xrange(len(s)):
            curChar = s[curPos]
            
            if curChar in char2id and char2id[curChar] > lastSubstrEndPos:
                lastSubstrEndPos = char2id[curChar]
                
            char2id[curChar] = curPos
            
            res = max(res, curPos - lastSubstrEndPos)
            
        return res